package com.struts2.example.action;

import java.sql.Connection;
import java.sql.PreparedStatement;

import com.opensymphony.xwork2.ActionSupport;
import com.struts2.example.model.Connect;

public class InsertAnswersAction extends ActionSupport{

	/**
	 * 
	 */
	private String TAG="InsertAnswersAction : ";
	private static final long serialVersionUID = 1L;
	private int questionIdBean;
	private String answer;
	private String typeOfAnswer;
	
	public String execute()
	{
		System.out.print(TAG+ getQuestionIdBean()+"\n");
		System.out.print(TAG+getAnswer()+"\n");
		String ret = ERROR;
		Connect conn = new Connect();
		Connection connected = conn.Connected();
		
		try {
			String sql = "insert into testonline_bang_dai.answer values ( default, ?, ?, ?)";
			PreparedStatement ps = connected.prepareStatement(sql);
			ps.setInt(1,getQuestionIdBean());
			ps.setString(2, getAnswer());
			ps.setString(3,getTypeOfAnswer());

			ps.executeUpdate();
			System.out.print(TAG+"execute()"+"\n");	
			ret = SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			ret = ERROR;
		} finally {
			if (connected != null) {
				try {
					connected.close();
				} catch (Exception e) {
				}
			}
		}
		return ret;
	}
	
	public int getQuestionIdBean()
	{
		return this.questionIdBean;
	}
	
	public void setQuestionIdBean(int questionIdBean)
	{
		this.questionIdBean=questionIdBean;
	}
	
	public String getAnswer()
	{
		return this.answer;
	}
	
	public void setAnswer(String answer)
	{
		this.answer=answer;
	}
	
	public String getTypeOfAnswer()
	{
		return this.typeOfAnswer;
	}
	
	public void setTypeOfAnswer(String typeOfAnswer)
	{
		this.typeOfAnswer=typeOfAnswer;
	}

}
